﻿using Castle.DynamicProxy;
using SourceCodeIoc.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SourceCodeIoc.Aop
{
    /// <summary>
    /// AOP 动态代理
    /// </summary>
    public class AOPProxyGenerator
    {
        /// <summary>
        /// 1、创建代理类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static object CreateAOPProxy(object _object)
        {
            // 1、创建代理对象
            ProxyGenerator generator = new ProxyGenerator();
            //Student data =  generator.CreateClassProxy<Student>(new StudentLoggerIntercept());
            object _ProxyObject = generator.CreateClassProxyWithTarget(_object.GetType(), _object, new StudentLoggerIntercept());
            return _ProxyObject;
        }
    }
}
